/**
 *地图管理器 
 */
MapManager = OpenLayers.Class({
	
	initialize: function() {
		//注册事件
		_events.register("configLoadedEvent",this,this.configLoadListener);
	},
	
	configLoadListener:function(configData){
		var $this=this;
		this.configData = configData;
		_events.unregister("configLoadedEvent",this,this.configLoadListener);
		
		var params = {
			isZoomSlider:true,
			isPanArrows:false
		};
		
		if(this.configData.map.initialExtent){
			//初始化范围
			var ext = this.configData.map.initialExtent.split(",");
			params.extent = new OpenLayers.Bounds(ext[0], ext[1], ext[2], ext[3]);
		}
		this.map = new OpenLayers.Map("map",
		{
			controls: [
						new OpenLayers.Control.Navigation()
		            ],
		    theme:null,
			displayProjection: new OpenLayers.Projection("EPSG:4326")
		});

        //设置地图范围
        
        // 确定地图初始化完成事件
		if(this.configData.map.basemaps){
	    	var mapservices = this.configData.map.basemaps.mapservice;
	    	
	    	if(mapservices.text){
	    		var mapservice = this.configData.map.basemaps.mapservice;
	        	this.map.addLayer(this.addLayer(mapservice));
	    	}else{
	    		for(var i = 0;i<mapservices.length;i++){
	        		var mapservice = this.configData.map.basemaps.mapservice[i];
	        		this.map.addLayer(this.addLayer(mapservice));
	        	}
	    	}
	    	var cr;
	    	if(this.configData.map.center){
	    		cr = this.configData.map.center.split(",");
			}
			
			//此处经纬度的转了下，今后需要处理
			var center=new OpenLayers.LonLat(cr[0],cr[1]).transform(this.map.displayProjection,this.map.getProjectionObject());
			this.map.setCenter(center, 1);
		}
		//触发地图装载完成事件
		_events.triggerEvent("mapLoadedEvent",this.map);
	},
	addLayer : function(mapservice){
		var layerurl = mapservice.replace(/##/g,"&");
			var layer = null;
			//如果是google底图
			if("Google" == mapservice.type){
		        var b = eval(mapservice.isbasemap);
				var maxResolution=this.configData.map.maxResolution;
				var numZoomLevels=this.configData.map.numZoomLevels;
				var boundsstr=this.configData.map.bounds;
				var bounds=null;
				if(boundsstr!=null){
					var loadStr="bounds=new OpenLayers.Bounds("+boundsstr+")";
					eval(loadStr);
				}
				if(maxResolution==null || numZoomLevels==null){
					layer = new OpenLayers.Layer.GoogleMap({
					    name: mapservice.label,
					    type: "map",
					    url　:layerurl
					});
				}else{
					layer = new OpenLayers.Layer.GoogleMap({
					    name: mapservice.label,
					    type: "map",
					    url　:layerurl,
					    bounds :bounds,
						maxResolution: maxResolution,
						numZoomLevels: numZoomLevels
					});
				}
			
		        
		        
			}
			//如果是ArcGIS底图
			else if("ArcGIS"==mapservice.type){
				
			}
			//如果是百度底图
			else if("baidu"==mapservice.type){
				
			}

		    return layer; 	
	},
	CLASS_NAME:"openGis.MapManager"
});

